<div class="form">

	<?php 
	/**
	 *
	 * @var $form CActiveForm
	 */
	$form=$this->beginWidget('CActiveForm', array(
			'id'=>'news-form',
			'enableAjaxValidation'=>false,
	));
	?>


	<?php echo $form->errorSummary($model); ?>

	<div class="row">
		<?php echo $form->labelEx($model,'title'); ?>
		<?php echo $form->textField($model,'title',array('size'=>60,'maxlength'=>255)); ?>
		<?php echo $form->error($model,'title'); ?>
	</div>
	<div class="row" id='image'>
		<?php echo $form->labelEx($model, 'image_id'); ?>
		<?php
		$this->widget('ext.EAjaxUpload.EAjaxUpload',
				array(
						'id' => 'uploadFile',
						'config' => array(
								'action' => Yii::app()->createUrl('upload/image', array('ctype' => 'training')),
								'allowedExtensions' => array("jpg", "png","jpeg","gif"), //array("jpg","jpeg","gif","exe","mov" and etc...
								'sizeLimit' => 1 * 1024 * 1024, // maximum file size in bytes
								'minSizeLimit' => 1024, // minimum file size in bytes
								'onComplete' => "js:function(id, fileName, responseJSON){ $('#News_image_id').val(responseJSON.item_id); 
								var img = document.getElementById('#img');
								if(img == undifined){
								$('#image').append('<img src=\"/upload/images/thumb/'+responseJSON.filename+'\" id=\"img\" />');
									}else{
								$('#img').attr('src','/upload/images/thumb/'+responseJSON.filename);}
								}",
								
						)
				));
		echo $form->hiddenField($model,'image_id');
		if($model->image_id){
			Yii::import('application.extensions.image.Image');
			$image = new Image(Yii::getPathOfAlias('webroot').'/'.$model->image->path);
			$image->resize(250, 100);
			$thumb = '/upload/images/thumb/'.substr_replace($model->image->path,'',0,14);
			$path_thumb = Yii::getPathOfAlias('webroot').$thumb;
			if(!is_file($path_thumb)){
				$image->save($path_thumb);
			}
			
			echo "<img src='".$thumb."' id='img' >";
		}
		?>

	</div>
	<div class="row">
		<?php echo $form->labelEx($model,'body'); ?>
		<?php //echo $form->textArea($model,'body',array('rows'=>6, 'cols'=>50));
		$this->widget('application.extensions.ckeditor.CKEditor', array(
				'model' => $model,
				'attribute' => 'body',
				'language' => 'vi',
				'editorTemplate' => 'full',
		));
		?>
		<?php echo $form->error($model,'body'); ?>
	</div>

	<div class="row">
		<?php echo $form->labelEx($model,'status'); ?>
		<?php echo $form->listBox($model,'status',array(1=>'Xuất bản',2=>'Không xuất bản'),array('size'=>1)); ?>
		<?php echo $form->error($model,'status'); ?>
	</div>

	<div class="row buttons">
		<?php echo CHtml::submitButton($model->isNewRecord ? 'Tạo mới' : 'Lưu'); ?>
	</div>

	<?php $this->endWidget(); ?>

</div>
<!-- form -->
